package com.example.guiguiapplicatio.fragment.home;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.guiguiapplicatio.fragment.home.adapter.ServiceFragmentAdapter;
import com.example.guiguiapplicatio.databinding.FragmentServiceBinding;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
;import com.example.guiguiapplicatio.R;
import com.example.guiguiapplicatio.placeholder.PlaceholderContent;
import com.example.guiguiapplicatio.placeholder.PlaceholderContent.PlaceholderItem;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class ServiceFragment extends Fragment {
    private FragmentServiceBinding binding;

    private ServiceFragmentAdapter adapter;
    public static List<PlaceholderItem> ITEMS_1 = new ArrayList<PlaceholderItem>();
    public static List<PlaceholderItem> NOW_ITEMS = new ArrayList<PlaceholderItem>();
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentServiceBinding.inflate(inflater, container, false);
        View view = binding.getRoot();
        binding.serviceList.setLayoutManager(new LinearLayoutManager(binding.getRoot().getContext()));

        NOW_ITEMS=PlaceholderContent.ITEMS;

        adapter=new ServiceFragmentAdapter(NOW_ITEMS);
        binding.serviceList.setAdapter(adapter);

        binding.servicButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("onClick: " ,"onClick: 您点击了2");
                for (int i=0;i<PlaceholderContent.ITEMS.size();i++){
                    if (!NOW_ITEMS.get(i).id.equals(String.valueOf(1))){
                       NOW_ITEMS.remove(i);
                        Log.e("onClick: " ,"onClick: 您点击了"+PlaceholderContent.ITEMS.get(i).id+"  "+String.valueOf(1)+NOW_ITEMS.get(i).id.equals(String.valueOf(1)));
                    }
                }
                adapter.notifyDataSetChanged();
            }
        });

        binding.servicBack.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_navigation_service_to_navigation_home));

        return view;
    }

    @Override
    public void onResume() {
        BottomNavigationView bottomNavigationView=requireActivity().findViewById(R.id.nav_view);
        bottomNavigationView.setVisibility(View.INVISIBLE);
        //这两行代码设置隐藏底部导航栏，若要显示啧修改INVISIBLE为Visible（可见）
        super.onResume();
    }


}
